package demo3;

/**
 * @Author liangzai
 * @Description:
 */
class Money implements Cloneable{
    public double money=9.9;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

class Person implements Cloneable{
    public int age;
    public String name;
    Money m=new Money();

    public Person(int age, String name) {
        this.age = age;
        this.name = name;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        //return super.clone();

        Person tmp=(Person) super.clone();
        tmp.m=(Money) this.m.clone();
        return tmp;
    }


    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                ", name='" + name +
                '}';
    }
}

public class Tests {
    public static void main(String[] args) throws CloneNotSupportedException{
        Person person1 = new Person(19,"liuzhi");
        Person person2 = (Person) person1.clone();
        person1.m.money=99.99;
        System.out.println("preson1:"+person1+"money:"+ person1.m.money);
        System.out.println("preson2:"+ person2+"money:"+person2.m.money);

    }
}
